// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file DynamicTypesCollectionTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen.
 */

#include <ddsrecorder_participants/common/types/dynamic_types_collection/DynamicTypesCollectionTypeObjectSupport.hpp>

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>

#include <ddsrecorder_participants/common/types/dynamic_types_collection/DynamicTypesCollection.hpp>


using namespace eprosima::fastdds::dds::xtypes;

namespace eprosima {
namespace ddsrecorder {
namespace participants {
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_DynamicType_type_identifier(
        TypeIdentifierPair& type_ids_DynamicType)
{

    ReturnCode_t return_code_DynamicType {eprosima::fastdds::dds::RETCODE_OK};
    return_code_DynamicType =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "eprosima::ddsrecorder::participants::DynamicType", type_ids_DynamicType);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_DynamicType)
    {
        StructTypeFlag struct_flags_DynamicType = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_DynamicType = "eprosima::ddsrecorder::participants::DynamicType";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_DynamicType;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_DynamicType;
        CompleteTypeDetail detail_DynamicType = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_DynamicType, ann_custom_DynamicType, type_name_DynamicType.to_string());
        CompleteStructHeader header_DynamicType;
        header_DynamicType = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_DynamicType);
        CompleteStructMemberSeq member_seq_DynamicType;
        {
            TypeIdentifierPair type_ids_type_name;
            ReturnCode_t return_code_type_name {eprosima::fastdds::dds::RETCODE_OK};
            return_code_type_name =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_string_unbounded", type_ids_type_name);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_type_name)
            {
                {
                    SBound bound = 0;
                    StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
                            "anonymous_string_unbounded", type_ids_type_name))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_type_name = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_type_name = 0x00000000;
            bool common_type_name_ec {false};
            CommonStructMember common_type_name {TypeObjectUtils::build_common_struct_member(member_id_type_name, member_flags_type_name, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_type_name, common_type_name_ec))};
            if (!common_type_name_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure type_name member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_type_name = "type_name";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_type_name;
            ann_custom_DynamicType.reset();
            CompleteMemberDetail detail_type_name = TypeObjectUtils::build_complete_member_detail(name_type_name, member_ann_builtin_type_name, ann_custom_DynamicType);
            CompleteStructMember member_type_name = TypeObjectUtils::build_complete_struct_member(common_type_name, detail_type_name);
            TypeObjectUtils::add_complete_struct_member(member_seq_DynamicType, member_type_name);
        }
        {
            TypeIdentifierPair type_ids_type_information;
            ReturnCode_t return_code_type_information {eprosima::fastdds::dds::RETCODE_OK};
            return_code_type_information =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_string_unbounded", type_ids_type_information);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_type_information)
            {
                {
                    SBound bound = 0;
                    StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
                            "anonymous_string_unbounded", type_ids_type_information))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_type_information = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_type_information = 0x00000001;
            bool common_type_information_ec {false};
            CommonStructMember common_type_information {TypeObjectUtils::build_common_struct_member(member_id_type_information, member_flags_type_information, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_type_information, common_type_information_ec))};
            if (!common_type_information_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure type_information member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_type_information = "type_information";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_type_information;
            ann_custom_DynamicType.reset();
            CompleteMemberDetail detail_type_information = TypeObjectUtils::build_complete_member_detail(name_type_information, member_ann_builtin_type_information, ann_custom_DynamicType);
            CompleteStructMember member_type_information = TypeObjectUtils::build_complete_struct_member(common_type_information, detail_type_information);
            TypeObjectUtils::add_complete_struct_member(member_seq_DynamicType, member_type_information);
        }
        {
            TypeIdentifierPair type_ids_type_object;
            ReturnCode_t return_code_type_object {eprosima::fastdds::dds::RETCODE_OK};
            return_code_type_object =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_string_unbounded", type_ids_type_object);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_type_object)
            {
                {
                    SBound bound = 0;
                    StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
                            "anonymous_string_unbounded", type_ids_type_object))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_type_object = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_type_object = 0x00000002;
            bool common_type_object_ec {false};
            CommonStructMember common_type_object {TypeObjectUtils::build_common_struct_member(member_id_type_object, member_flags_type_object, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_type_object, common_type_object_ec))};
            if (!common_type_object_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure type_object member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_type_object = "type_object";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_type_object;
            ann_custom_DynamicType.reset();
            CompleteMemberDetail detail_type_object = TypeObjectUtils::build_complete_member_detail(name_type_object, member_ann_builtin_type_object, ann_custom_DynamicType);
            CompleteStructMember member_type_object = TypeObjectUtils::build_complete_struct_member(common_type_object, detail_type_object);
            TypeObjectUtils::add_complete_struct_member(member_seq_DynamicType, member_type_object);
        }
        CompleteStructType struct_type_DynamicType = TypeObjectUtils::build_complete_struct_type(struct_flags_DynamicType, header_DynamicType, member_seq_DynamicType);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_DynamicType, type_name_DynamicType.to_string(), type_ids_DynamicType))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "eprosima::ddsrecorder::participants::DynamicType already registered in TypeObjectRegistry for a different type.");
        }
    }
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_DynamicTypesCollection_type_identifier(
        TypeIdentifierPair& type_ids_DynamicTypesCollection)
{

    ReturnCode_t return_code_DynamicTypesCollection {eprosima::fastdds::dds::RETCODE_OK};
    return_code_DynamicTypesCollection =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "eprosima::ddsrecorder::participants::DynamicTypesCollection", type_ids_DynamicTypesCollection);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_DynamicTypesCollection)
    {
        StructTypeFlag struct_flags_DynamicTypesCollection = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_DynamicTypesCollection = "eprosima::ddsrecorder::participants::DynamicTypesCollection";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_DynamicTypesCollection;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_DynamicTypesCollection;
        CompleteTypeDetail detail_DynamicTypesCollection = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_DynamicTypesCollection, ann_custom_DynamicTypesCollection, type_name_DynamicTypesCollection.to_string());
        CompleteStructHeader header_DynamicTypesCollection;
        header_DynamicTypesCollection = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_DynamicTypesCollection);
        CompleteStructMemberSeq member_seq_DynamicTypesCollection;
        {
            TypeIdentifierPair type_ids_dynamic_types;
            ReturnCode_t return_code_dynamic_types {eprosima::fastdds::dds::RETCODE_OK};
            return_code_dynamic_types =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded", type_ids_dynamic_types);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_dynamic_types)
            {
                return_code_dynamic_types =
                    eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                    "eprosima::ddsrecorder::participants::DynamicType", type_ids_dynamic_types);

                if (eprosima::fastdds::dds::RETCODE_OK != return_code_dynamic_types)
                {
                    eprosima::ddsrecorder::participants::register_DynamicType_type_identifier(type_ids_dynamic_types);
                }
                bool element_identifier_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded_ec {false};
                TypeIdentifier* element_identifier_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_dynamic_types, element_identifier_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded_ec))};
                if (!element_identifier_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded_ec)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent.");
                    return;
                }
                EquivalenceKind equiv_kind_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded = EK_COMPLETE;
                if (TK_NONE == type_ids_dynamic_types.type_identifier2()._d())
                {
                    equiv_kind_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded = EK_BOTH;
                }
                CollectionElementFlag element_flags_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded = 0;
                PlainCollectionHeader header_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded, element_flags_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded);
                {
                    SBound bound = 0;
                    PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded, bound,
                                eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded));
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded", type_ids_dynamic_types))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_sequence_eprosima_ddsrecorder_participants_DynamicType_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_dynamic_types = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_dynamic_types = 0x00000000;
            bool common_dynamic_types_ec {false};
            CommonStructMember common_dynamic_types {TypeObjectUtils::build_common_struct_member(member_id_dynamic_types, member_flags_dynamic_types, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_dynamic_types, common_dynamic_types_ec))};
            if (!common_dynamic_types_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure dynamic_types member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_dynamic_types = "dynamic_types";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_dynamic_types;
            ann_custom_DynamicTypesCollection.reset();
            CompleteMemberDetail detail_dynamic_types = TypeObjectUtils::build_complete_member_detail(name_dynamic_types, member_ann_builtin_dynamic_types, ann_custom_DynamicTypesCollection);
            CompleteStructMember member_dynamic_types = TypeObjectUtils::build_complete_struct_member(common_dynamic_types, detail_dynamic_types);
            TypeObjectUtils::add_complete_struct_member(member_seq_DynamicTypesCollection, member_dynamic_types);
        }
        CompleteStructType struct_type_DynamicTypesCollection = TypeObjectUtils::build_complete_struct_type(struct_flags_DynamicTypesCollection, header_DynamicTypesCollection, member_seq_DynamicTypesCollection);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_DynamicTypesCollection, type_name_DynamicTypesCollection.to_string(), type_ids_DynamicTypesCollection))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "eprosima::ddsrecorder::participants::DynamicTypesCollection already registered in TypeObjectRegistry for a different type.");
        }
    }
}

} // namespace participants

} // namespace ddsrecorder

} // namespace eprosima

